package com.bit.aop.demo.proxy;


//import java.lang.reflect.Proxy;

import net.sf.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.Proxy;

public class Main {
    public static void main(String[] args) {
        //静态代理
//        HouseSubject target = new RealHouseSubject();
//        HouseSubject proxy = new HouseProxy(target);
//        proxy.rentHouse();


        //JDK动态代理
//        HouseSubject target = new RealHouseSubject();
//        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
//                new Class[]{HouseSubject.class}, new JDKInvocationHandler(target));
//        proxy.rentHouse();
//        proxy.saleHouse();

        //cglib 动态代理
        HouseSubject target = new RealHouseSubject();
        HouseSubject proxy = (HouseSubject) Enhancer.create(target.getClass(), new CglibMethodInterceptor(target));
        proxy.rentHouse();
        proxy.saleHouse();

    }
}
